package com.lyy.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.lyy.fallback.SentinelFallback;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author Liangyaoyun
 */
@RestController
@RequestMapping("/api/v1/flow")
public class FlowController {
    /** 当资源 `qpsDirectFail` 降级时，执行SentinelFallback类的fallback()方法 */
    @SentinelResource(value = "qpsDirectFail",
            fallbackClass = SentinelResource.class,
    fallback = "fallback")
    @GetMapping("/qpsDirectFail")
    public String qpsDirectFail(){
        return "资源qpsDirectFail调用成功";
    }
    /** 当资源 `qpsDirectWarmUp` 降级时，执行SentinelFallback类的fallback()方法 */
    @SentinelResource(value = "qpsDirectWarmUp",
    fallback = "fallback",
    fallbackClass = SentinelResource.class)
    @GetMapping("/qpsDirectWarmUp")
    public String qpsDirectWarmUp(){
        return "资源qpsDirectWarmUp调用成功";
    }
    /** 当资源 `qpsDirectLineUp` 降级时，执行SentinelFallback类的fallback()方法 */
    @SentinelResource(value = "qpsDirectLineUp",
    fallback = "fallback",
    fallbackClass = SentinelResource.class)
    @GetMapping("/qpsDirectLineUp")
    public String qpsDirectLineUp(){
        return "资源qpsDirectLineUp";
    }

    @SentinelResource(value = "qpsRelation01",
    fallback = "fallback",
    fallbackClass = SentinelResource.class)
    @GetMapping("/qpsRelation01")
    public String qpsRelation01(){
        return "资源qpsRelation01调用成功";
    }
    @SentinelResource(value = "qpsRelation02",
            fallback = "fallback",
            fallbackClass = SentinelResource.class)
    @GetMapping("/qpsRelation02")
    public String qpsRelation02(){
        return "资源qpsRelation02调用成功";
    }
    /** 当资源 `threadDirect` 降级时，执行SentinelFallback类的fallback()方法 */
    @SentinelResource(value = "threadDirect",
            fallbackClass = SentinelFallback.class,
            fallback = "fallback")
    @RequestMapping("/threadDirect")
    public String threadDirect() {
        return "资源threadDirect用成功";
    }


}

